package org.springleaf.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.security.authentication.encoding.PasswordEncoder;

/**
 * spring security MD5加密器
 * @author leaf
 *
 */
public class MD5PasswordEncoder implements PasswordEncoder {

	@Override
	public String encodePassword(String paramString, Object paramObject)
			throws DataAccessException {
		return DigestUtils.md5Hex(paramString);
	}

	@Override
	public boolean isPasswordValid(String paramString1, String paramString2,
			Object paramObject) throws DataAccessException {
		if(StringUtils.isNotBlank(paramString1) && StringUtils.isNotBlank(paramString2)){
			return paramString1.equals(DigestUtils.md5Hex(paramString2));
		}
		return false;
	}

}
